% TEST_ID: LANG-EXPAND-0077
% CATEGORY: stdlib/arithmetic_ops/bitops
% 测试 bitand 函数
function test_bit_bitand()
A = uint8([0 1; 0 1]);
B = uint8([0 0; 1 1]);
TTable = bitand(A, B)
assert(isequal(TTable, [0 0; 0 1]));
assert(isa(TTable, 'uint8'));
a = -5;
a1 = bitget(a,8:-1:1,'int8');
assert(isequal(a1, [1 1 1 1 1 0 1 1]));
b = 6;
b1 = bitget(b,8:-1:1,'int8');
assert(isequal(b1, [0 0 0 0 0 1 1 0]));
c = bitand(a,b,'int8');
assert(c == 2);
c1 = bitget(c,8:-1:1,'int8');
assert(isequal(c1, [0 0 0 0 0 0 1 0]));

r = bitand([1 2 3], [4 5 6], 'int8');
assert(isequal(r, [0 0 2]));

tf = false;
try
    bitand([], [1 2 3]);
catch
    tf = true;
end
assert(tf);

assert(isempty(bitand([], [])))

% 接下来的是和Matlab行为不一致的, Matlab 会报错, 属于是我们增加的功能
r = bitand([1 2 3], int8(3));
assert(isequal(r, [1 2 3]));
assert(isa(r, 'int8'));

r = bitand([1 2 3], int8(3), 'int8');
assert(isequal(r, [1 2 3]));
r = bitand(0, false);
assert(class(r) == 'double');
assert(r == 0);